<?php

class MainController extends Zend_Controller_Action {
  
    public function indexAction()
    {
        $user = new Zend_Session_Namespace("user");
        
        $this->view->helloMessage = "Bem-vindo ".$user->name;
    }

    public function detalhesAction()
    {
      
    }
    
    public function reciveformAction()
    {
       
        $action = $_POST['action'];
            
        switch($action){
            case "logar":
                
                require_once APPLICATION_PATH . '/models/User.php';
                
                $name = $_POST['name'];
                $password = $_POST['passwd'];
                
                $user = new User();
                if($user->getUser($name,$password)){
                    $user = new Zend_Session_Namespace("user");
                    $user->name = $name;
                    $user->password = $password;
                    $this->_redirect('/main/index');
                }else{
                    $this->_redirect('/index/index');
                }                
                break;
           case "cadastrar":
               echo "teste";
               require_once APPLICATION_PATH . '/models/User.php';
               $name = $_POST['user'];
               $password = $_POST['password'];               
               $user = new User();
               //$user->addUser($user,$password);
               $this->_redirect('/index/message?message=Voce foi devidamente cadastrado no BD.');
               
        }
    }
    
    public function logoffAction(){
        $user = new Zend_Session_Namespace();
        $user->name = "anonymous";
        $user->password = "";
        
        $this->_redirect('/index/index');
    }
}

?>
